﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;
using CNotebook;

namespace NotebookS2
{
    public partial class FND_EMPLOYEE : RibbonForm
    {
        public FND_EMPLOYEE()
        {
            InitializeComponent();
        }
        public string ConnectionString { get; set; }
        public string EmployeeID { get; set; }
        public string EmployeeFullName { get; set; }
        public string EmployeeDepartment { get; set; }

        void BindGridByName(string _FullName)
        {
            EmployeeManager oManager = new EmployeeManager();

            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();

            gridControl1.DataSource = oManager.GetEmployeesByFullName(_FullName);
            gridControl1.Refresh();

            oManager.Close();
        }
    
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void txtSearch_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            BindGridByName(txtSearch.Text);
        }

        private void btnChoose_Click(object sender, EventArgs e)
        {
            int iRowIndex = gridView1.FocusedRowHandle;

            this.EmployeeID = gridView1.GetRowCellValue(iRowIndex, gridView1.Columns["EmpID"]).ToString();
            this.EmployeeFullName = gridView1.GetRowCellValue(iRowIndex, gridView1.Columns["FullName"]).ToString();
            this.EmployeeDepartment = gridView1.GetRowCellValue(iRowIndex, gridView1.Columns["Department"]).ToString();
            this.Close();
        }

        private void gridControl1_DoubleClick(object sender, EventArgs e)
        {
            btnChoose_Click(sender, e);
        }

        private void FND_EMPLOYEE_Load(object sender, EventArgs e)
        {

        }

        private void txtSearch_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                BindGridByName(txtSearch.Text);
            }

            if (e.KeyCode == Keys.Tab)
            {
                BindGridByName(txtSearch.Text);
            }
        }

        private void gridView1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnChoose_Click(sender, e);
            }

            if (e.KeyCode == Keys.Tab)
            {
                btnChoose_Click(sender, e);
            }
        }

        private void gridView1_DoubleClick(object sender, EventArgs e)
        {
            btnChoose_Click(sender, e);
        }
    }
}
